
#include "p33Fxxxx.h"

#define FCY				36500000
#define BAUDRATE        9600                   
#define BRGVAL          ((FCY/BAUDRATE)/16)-1 



_FOSCSEL(FNOSC_FRC );		// FRC Oscillator 
_FOSC(FCKSM_CSECMD & OSCIOFNC_OFF  & POSCMD_NONE); 
								// Clock Switching is enabled and Fail Safe Clock Monitor is disabled
								// OSC2 Pin Function: OSC2 is Clock Output
								// Primary Oscillator Mode: Disabled


_FWDT(FWDTEN_OFF);              // Watchdog Timer Enabled/disabled by user software
								// (LPRC can be disabled by clearing SWDTEN bit in RCON register


int main (void)
{
			
// Configure Oscillator to operate the device at 39.61Mhz
// Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
// Fosc= 7.37M*43/(2*2)=79.22Mhz for 7.37M input clock
	PLLFBD=41;					// M=43
	CLKDIVbits.PLLPOST=0;		// N1=2
	CLKDIVbits.PLLPRE=0;		// N2=2
	OSCTUN=0;					// Tune FRC oscillator, if FRC is used

// Clock switch to incorporate PLL
	__builtin_write_OSCCONH(0x01);		// Initiate Clock Switch to
										// FRC with PLL (NOSC=0b001)
	__builtin_write_OSCCONL(0x01);		// Start clock switching

	while (OSCCONbits.COSC != 0b001);	// Wait for Clock switch to occur	

// Wait for PLL to lock
	while(OSCCONbits.LOCK!=1) {};
  
    // Configure the Analog functional pins as digital 
	AD1PCFGL=0xFFFF;
	AD1PCFGH=0xFFFF;

	 dciInit();
// Realmente habria que inicializar el si3000:
	 si3000Init();
//	DCICON1bits.DCIEN = 1; 
//	IEC3bits.DCIIE=1;

	configurarfilterinit();
	FIRFilterInit();

	while(1){
	//esto no va... es solo para producir la interrupcion DCI
//	IFS3bits.DCIIF=1;
	}
 }  


